package com.wlw.admin.openeye.ui.adapter

import android.content.Context
import android.support.design.internal.FlexboxLayout
import android.view.View
import android.widget.TextView
import com.google.android.flexbox.FlexboxLayoutManager
import com.hazz.kotlinmvp.view.recyclerview.ViewHolder
import com.hazz.kotlinmvp.view.recyclerview.adapter.CommonAdapter
import com.wlw.admin.openeye.R

class HotKeywordsAdapter(mContext: Context, mList: ArrayList<String>) : CommonAdapter<String>(mContext, mList, R.layout.item_flow_text) {

    private var mOnTagItemClick: ((tag: String) -> Unit)? = null

    fun setOnTagItemClickListener(onTagItemClick: ((tag: String) -> Unit)) {
        this.mOnTagItemClick = onTagItemClick
    }

    override fun bindData(holder: ViewHolder, data: String, position: Int) {
        holder.setText(R.id.tv_title, data)
        val params = holder.getView<TextView>(R.id.tv_title)
        if (params is FlexboxLayoutManager.LayoutParams) {
            params.flexGrow = 1.0f
        }

        holder.setOnItemClickListener(View.OnClickListener {
            mOnTagItemClick?.invoke(data)
        })
    }
}